﻿using System;
using System.Text;
using System.Web.UI;
using QzEbook.ReWrite;

namespace QzEbook.BaseView
{
    /// <summary>
    /// 所有页面的基类;
    /// </summary>
    /// 
    public class BasePage : Page
    {
        public BasePage()
        {
            this.Load += new EventHandler(BasePageInit);
        }

        private void BasePageInit(object sender, EventArgs e)
        {
            if (canBuildNav())
            {
                this.builderNav();
            }
        }
        /// <summary>
        /// 创建菜单勾子;
        /// </summary>
        /// <returns></returns>
        protected virtual bool canBuildNav()
        {
            return true;
        }
        protected virtual void builderNav()
        {
            return;
        }

        public void alert(string message)
        {
            StringBuilder sb=new StringBuilder();
            sb.AppendLine("<script language=\"javascript\">");
            sb.AppendFormat("alert(\"{0}\")",message);
            sb.AppendLine("</script>");
            if (this.ClientScript.IsStartupScriptRegistered("alert")) return;
            this.ClientScript.RegisterStartupScript(this.GetType(),"alert", sb.ToString());
        }
        public void close()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<script language=\"javascript\">");
            sb.AppendLine("self.close()");
            sb.AppendLine("</script>");
            if (this.ClientScript.IsStartupScriptRegistered("close")) return;
            this.ClientScript.RegisterStartupScript(this.GetType(), "close", sb.ToString());
        }

        /// <summary>
        /// 重写输出去掉无用缩进;
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            writer = new FilterHtmlTextWriter(writer.InnerWriter, "");
            base.Render(writer);
        }
    }
}